layui.use(['table', 'form', 'vip_table', 'jquery', 'fms_util', 'element'], function () {
    // 操作对象
    var form = layui.form,
        table = layui.table,
        vipTable = layui.vip_table,
        fmsUtil = layui.fms_util,
        element = layui.element,
        $ = layui.jquery;

    //表格加载
    var where = {};
    where[API.key.userId] = API.userId();
    where[API.key.systemSourceId] = API.systemSourceId();
    where['type']=2;
    var tableIns = {};
    var tableIns1 = {};
    initTable(where);
    function initTable(where) {
        tableIns = vipTable.bdTable({
            table: table,
            elem: "#dataTable",
            limit: 6,
            cols: [[
                {type: 'numbers', title: '序',width:'5%', align: 'center'},
                // {type:'checkbox'},
                {field: 'supplierNo4', title: '模板名称', align: 'center'},
                {field: 'supplierNo5', title: '生效状态', align: 'center'},
                {title: '操作', align: 'center', toolbar: '#barOption'}
            ]],
            data:[
                {supplierNo4:1,supplierNo5:2}
            ]
        });
    }
    function initTable1(where) {
        tableIns1 = vipTable.bdTable({
            table: table,
            elem: "#dataTable1",
            limit: 6,
            cols: [[
                {type: 'numbers', title: '序',width:'5%', align: 'center'},
                // {type:'checkbox'},
                {field: 'supplierNo1', title: '确认模板', align: 'center'},
                {field: 'supplierNo2', title: '自动确认延迟天数', align: 'center'},
                {field: 'supplierNo3', title: '生效状态', align: 'center'},
                {title: '操作', align: 'center', toolbar: '#barOption'}
            ]],
            data:[
                {supplierNo1:1,supplierNo2:2,supplierNo3:3}
            ]
        });
    }
    initTable1(where);
    //搜索
    form.on('submit(search)', function (data) {
        where = $.extend(where, data.field);
        var reloadWhere = fmsUtil.filterObject(where);//筛选掉空的数据
        where.pageNo = 1;
        tableIns.reload({
            searchState: true,
            where: reloadWhere
        });
        initTable(reloadWhere);
        return false;
    });

    table.on('tool(dataTable)', function (obj) {
        var layEvent = obj.event;
        var value = obj.value,//得到修改后的值
            data = obj.data,//得到所在行所有键值
            field = obj.field; //得到字段

        if (layEvent === 'edit') {
            active.edit(data.id);
        } else if (layEvent === 'dalete') {
            active.dalete(data.id);
        }
    });
    // 新增功能
    form.on('submit(add)', function (data) {
        active.add();
        return false;
    });
    var active = {
        add: function () {
            fmsUtil.replaceHref('alarm-setup-add.html');
        }

    };


});